package homework0708;

import homework0708_jk.GuessingGameService;

public class GuessingGameMain {
    GuessingGameService guessingGameService = new GuessingGameServiceImpl();
    Computer computer = new Computer();
    Player player = new Player();
    int score = 2;//起始分数2
    int cptNum;//机器出拳
    int iptNum;//玩家输入
    String judgeResult;//判断结果

    //开始玩游戏
    public String play() {
        while (true) {
            System.out.println("输入一个0~2的数字\n0:石头\t1:剪刀\t2:布\n" + "当前分数" + score);
            cptNum = computer.punches();//机器出拳
            System.out.println(cptNum);
            iptNum = player.punches();//玩家输入
            judgeResult = guessingGameService.judge(cptNum, iptNum);//判断,接收结果
            System.out.println("机器出" + (cptNum == 0 ? "石头" : cptNum == 1 ? "剪刀" : "布") + "，玩家出" + (iptNum == 0 ? "石头" : iptNum == 1 ? "剪刀" : "布") + "，结果是" + judgeResult);
            if ("win".equals(judgeResult)) {
                score++;
            } else if ("lose".equals(judgeResult)) {
                score--;
            }
            if (score >= 5) {
                return "分数达到，通关";
            } else if (score <= 0) {
                return "分数耗尽，GG";
            }
        }
    }

    public static void main(String[] args) {
        String gameResult = new GuessingGameMain().play();
        System.out.println(gameResult);
    }
}
